package com.ruoyi.ams.domain.vo;

import com.fasterxml.jackson.annotation.JsonInclude;

import com.ruoyi.common.core.domain.model.AmsOwnAddress;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.List;
import java.util.stream.Collectors;

@Data
@NoArgsConstructor
public class TreeListAddress implements Serializable {
    private static final long serialVersionUID = 1L;

    private Long id;
    private Long addressId;
    private Long parentId;
    private String ancestors;
    private Long deptId;
    private String name;
    private String fullName;
    private Integer sortId;
    private String longitude;
    private String latitude;

    /**
     * 子节点
     */
    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    private List<TreeListAddress> children;

    public TreeListAddress(AmsOwnAddress address) {
        this.id = address.getAddressId();
        this.addressId = address.getAddressId();
        this.parentId = address.getParentId();
        this.ancestors = address.getAncestors();
        this.deptId = address.getDeptId();
        this.name = address.getName();
        this.fullName = address.getFullName();
        this.sortId = address.getSortId();
        this.longitude = address.getLongitude();
        this.latitude = address.getLatitude();
        if (address.getChildren() != null) {
            this.children = address.getChildren().stream().map(TreeListAddress::new).collect(Collectors.toList());
        }
    }
}
